package me.zhengjie.cron;

import cn.hutool.core.util.ObjectUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.modbusTCP.EntranceTCP;
import me.zhengjie.modbusTCP.PalletTCP;
import me.zhengjie.pojo.sqlServer.*;
import me.zhengjie.ppService.*;
import me.zhengjie.repository.PPOutboundMissionRepository;
import me.zhengjie.repository.PPStationRepository;
import me.zhengjie.repository.PPTaskResultRepository;
import me.zhengjie.wcs.PPWcsStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author krilo
 * @date 2024-10-08 8:14
 */


@Slf4j
@Component
@RequiredArgsConstructor
public class imitationCron {

    private final PPWcsStatus ppWcsStatus;
    private final EntranceTCP entranceTCP;
    private final PPTaskResultService ppTaskResultService;
    private final PPInBoundService ppInBoundService;
    private final ImitationTestService imitationTestService;
    private final PalletTCP palletTCP;
    private final PPMoveService ppMoveService;
    private final PPOutBoundService ppOutBoundService;
    private final PPStationRepository ppStationRepository;
    private  final PPOutboundMissionRepository ppOutboundMissionRepository;

    private static final Logger ppLog = LoggerFactory.getLogger("pp");


//    /**
//     * 用于模拟入库任务
//     */
//    @Scheduled(cron = "*/2 * * * * *")
//    public void StartInBoundTaskTest() {
//        // 查找有没有正在进行的入库任务
//        PPTaskResult ppTaskResult = ppTaskResultService.findNowppTaskResult(1);
//        //查找最新的入库任务
//        PPInboundMission ppInboundMission = ppInBoundService.findNewInBoundMission();
//        try {
//            if (ObjectUtil.isEmpty(ppTaskResult) && ObjectUtil.isNotEmpty(ppInboundMission)) {
//                // 查找最新的入库载盘任务
//                imitationTestService.sendInBoundtask();
//                imitationTestService.taskStart();
//                ppLog.info("发送入库任务到wcs成功，任务wms_task_id：{}", ppInboundMission.getMissionCode());
//            }
//        } catch (Exception e) {
//            ppLog.error("入库任务发送到wcs失败，失败的任务wms_task_id：{}", e.toString());
//
//        }
//
//    }
//
//
//    /**
//     * 模拟移库测试
//     */
//    @Scheduled(cron = "*/2 * * * * *")
//    public void StartMoveTaskTest() {
//
//        // 查找有没有正在进行的移库任务
//        PPTaskResult ppTaskResult = ppTaskResultService.findNowppTaskResult(3);
//        //查找有没有未执行的移库任务
//        PPMoveMission ppMoveMission = ppMoveService.findNewMoveMission();
//        try {
//            if (ObjectUtil.isEmpty(ppTaskResult) && ObjectUtil.isNotEmpty(ppMoveMission)) {
//                imitationTestService.sendMoveTask();
//                imitationTestService.taskStart();
//                ppLog.info("发送移库任务成功，任务wms_task_id：{}", ppMoveMission.getMissionCode());
//            }
//        } catch (Exception e) {
//            ppLog.error("移库任务发送到wcs失败，失败的任务wms_task_id：{}", ppMoveMission.getMissionCode());
//        }
//
//
//    }
//
//
//    /**
//     * 模拟出库测试
//     */
//    @Scheduled(cron = "*/2 * * * * *")
//    public void StartOutBoundTaskTest() {
//
//        // 查找有没有正在进行的出库任务
//        PPTaskResult ppTaskResult = ppTaskResultService.findNowppTaskResult(2);
//
//        // 查找最新的出库任务
//        PPOutboundMission newPPOutboundMission = ppOutBoundService.findNewOutBoundMission();
//
//
//        try {
//            if (ObjectUtil.isEmpty(ppTaskResult) && ObjectUtil.isNotEmpty(newPPOutboundMission)) {
//
//                //发送出库任务到wcs
//                imitationTestService.sendOutBoundtask();
//                imitationTestService.taskStart();
//                ppLog.info("发送出库任务到wcs成功，任务wms_task_id：{}", newPPOutboundMission.getMissionCode());
//
//            }
//
//        } catch (Exception e) {
//            ppLog.error("发送出库任务到wcs失败，任务wms_task_id：{}", newPPOutboundMission.getMissionCode());
//
//        }
//
//    }


}
